package com.gy.boot.common.dao;

import com.gy.boot.common.util.BlankUtil;

public class IPageHelp {
    private static final ThreadLocal<IPage> LOCAL_PAGE = new ThreadLocal<>();

    private static void setLocalPage(IPage page) {
        LOCAL_PAGE.set(page);
    }
    public static IPage getLocalPage() {
        IPage page = LOCAL_PAGE.get();
        LOCAL_PAGE.remove();
        return page;
    }
    public static void setCountSqlID(String countSqlID) {
        if (BlankUtil.isBlank(countSqlID)) {
            return;
        }
        IPage page = LOCAL_PAGE.get();
        if (page == null) {
            return;
        }
        page.setCountSqlID(countSqlID);
    }

    public static <E> IPage<E> start(int pageNo, int pageSize) {
        return start(pageNo, pageSize, true);
    }
    public static <E> IPage<E> start(int pageNo, int pageSize, boolean count) {
        return start(pageNo, pageSize, count, null);
    }
    public static <E> IPage<E> start(int pageNo, int pageSize, String sqlCountID) {
        return start(pageNo, pageSize, true, sqlCountID);
    }
    private static <E> IPage<E> start(int pageNo, int pageSize, boolean count, String sqlCountID) {
        IPage<E> page = new IPage<>(pageNo, pageSize, count, sqlCountID);
        setLocalPage(page);
        return page;
    }

}
